<template>
	<view class="">
		<uni-popup ref="popup" type="bottom" background-color="#fff" borderRadius="20rpx 20rpx 0 0">
			<view class="popup-wrap">
				<view class="popup-header">
					<view class="popup-header-close" @click="close">
						<text>取消</text>
					</view>
					<view class="popup-header-title">
						<text>{{ title }}</text>
					</view>
					<view class="popup-header-confirm" @click="confirm">
						<text>确定</text>
					</view>
				</view>
				<view class="popup-content">
					<view class="popup-content-list">
						<picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value"
							@change="bindChange" class="picker-view">
							<picker-view-column v-for="(subColumn, index) in column" :key="index">
								<view 
									class="item" 
									:class="{'item-active': start == item}"
									v-for="(item,subIndex) in subColumn" 
									:key="subIndex"
								>{{item}}</view>
							</picker-view-column>
						</picker-view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		props: {
			title: {
				type: String,
				default: ""
			},
			column: {
				type: Array,
				default: []
			},
		},
		mounted() {
			this.visible = true
		},
		data() {
			return {
				value: [0, 0],
				visible: false,
				indicatorStyle: `height: 96rpx;`
			}
		},
		methods: {
			open() {
				this.$refs.popup.open()
			},

			close() {
				this.$refs.popup.close()
			},

			confirm() {
				let _value = []
				this.column.forEach((arr, index) => {
					_value[index] = arr[this.value[index]]
				})
				this.$emit("confirm", _value)
				this.close()
			},
			bindChange: function(e) {
				this.value = e.detail.value
				console.log("this.value", this.value)
				let _value = []
				this.column.forEach((arr, index) => {
					_value[index] = arr[this.value[index]]
				})
				this.$emit("change", {
					index: this.value,
					data: _value
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.popup-wrap {
		padding: 36rpx 0rpx 68rpx 0rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.popup-header {
		display: flex;
		align-items: center;
		padding: 0 22rpx;
	}

	.popup-header-title {
		flex: 1;
		text-align: center;
		font-weight: bold;
		font-size: 36rpx;
		color: #333333;
	}

	.popup-header-close {
		// position: absolute;
		font-weight: 400;
		font-size: 32rpx;
		color: #999999;
	}

	.popup-header-confirm {
		font-weight: bold;
		font-size: 32rpx;
		color: #E72A2A;
	}

	.popup-content {
		margin-top: 46rpx;
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.popup-content-list {
		height: 788rpx;
	}

	.picker-view {
		width: 750rpx;
		height: 600rpx;
		margin-top: 20rpx;
	}

	.item {
		// line-height: 96rpx;
		line-height: 64rpx;
		text-align: center;
		font-weight: 400;
		font-size: 32rpx;
		color: #999999;
	}

	.item-active {
		color: #E72A2A;
		background-color: #FFF2F2;
	}
</style>